package com.nervenets.web.controller.handler.user.user;

import com.nervenets.web.controller.handler.Handler;
import com.nervenets.web.controller.handler.common.TokenParams;
import com.nervenets.web.hibernate.domain.user.Address;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

public class UserAddressesHandler extends Handler<TokenParams> {
    @Override
    public String handle(TokenParams params, HttpServletRequest request) throws Exception {
        String hql = "from Address where userId = ? order by def desc";
        List<Object> objects = new ArrayList<>();
        objects.add(params.getUserId());

        final List<Address> addresses = userDao.getAllObjectsByHql(hql, objects);
        return successMessage(addresses);
    }

    @Override
    public String result() throws Exception {
        List<Address> addresses = new ArrayList<>();
        addresses.add(new Address(1000, "陈云", "13800138000", 510107, "剑南大道338号", true));
        addresses.add(new Address(1000, "陈云", "13800138000", 510107, "剑南大道338号", false));
        return successMessage(addresses);
    }
}
